/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.util;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EdiUtil {
	private static final Log log = LogFactory.getLog(EdiUtil.class);

	public static String getAppName(String url) {
		log.debug(" url =" + url);
		if(StringUtils.isBlank(url))
			return "";
		String DOTAPP = ".app";

		if (StringUtils.contains(url, DOTAPP)) {
			String appName = StringUtils.substringAfterLast(url, "/");
			return StringUtils.substringBefore(appName, DOTAPP);
//			return StringUtils.sub(url, "/", DOTAPP);
		} else {
			if (url.startsWith("/"))
				url = url.substring(1);
			if (url.indexOf("/") != -1)
				url = url.substring(0, url.indexOf("/"));
			else if(url.indexOf(".")!=-1){
				url = url.substring(0, url.indexOf("."));
			}
			return url;
		}
	}
	
	public static String getPageName(String url){
		String DOTPAGE = ".page";
		String result = "";
//		Method[] ms =StringUtils.class.getMethods();
//		for(Method m : ms){
//			System.out.print(m.getName());
//		}
		if (StringUtils.endsWith(url, DOTPAGE)){
			result = url;
			result = StringUtils.substringAfterLast(result, "/");
			result = StringUtils.substringBefore(result, DOTPAGE);
		}
		
		return result;
	}
	/**
	 * 获取page类型url 页面路径
	 * @param url
	 * @return
	 */
	public static String getPagePath(String url){
		String DOTPAGE = ".page";
		String result = "";
		if(url.contains("components/")){
			url=StringUtils.substringAfter(url,"components/");
		}
		log.debug("url ="+url);
		if (StringUtils.endsWith(url, DOTPAGE)){
			result = url; 
			result = StringUtils.substringBefore(result, DOTPAGE)+".swf?";
		}
		else if(url.contains(DOTPAGE)){
			result=StringUtils.replace(url, DOTPAGE, ".swf")+"&";
		} 
		return result;
	}

}
